package com.jycrm.dao.serve.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import com.jycrm.dao.core.AbstractService;
import com.jycrm.dao.serve.ICrmServiceProductTaOrderDao;
import com.jycrm.domain.serve.CrmServiceProductTaOrder;

public class CrmServiceProductTaOrderDaoImpl extends AbstractService implements ICrmServiceProductTaOrderDao{
	
	
	public void insert(CrmServiceProductTaOrder order){
		this.sqlMapManager.insert("insertCrmServiceProductTaOrder",order);
	}
	
	public void update(CrmServiceProductTaOrder order){
		this.sqlMapManager.update("updateCrmServiceProductTaOrder",order);
	}
	
	public CrmServiceProductTaOrder findCrmServiceProductTaOrder(Long serviceProductId, Long targetId, String targetType){
		Map param = new HashMap();
		param.put("targetId",targetId);
		param.put("targetType",targetType);
		param.put("serviceProductId",serviceProductId);
		List l = this.sqlMapManager.queryForList("findCrmServiceProductTaOrderByTarget",param);
		
		org.apache.commons.dbcp.BasicDataSource d;
		if(l.isEmpty()){
			return null;
			
		}else{
			return (CrmServiceProductTaOrder)l.get(0);
		}
	}

	public void delete(CrmServiceProductTaOrder order) {
		Map p=new HashMap();
		p.put("targetId",order.getTargetId());
		p.put("targetType",order.getTargetType());
		p.put("productId",order.getServiceProductId());
		this.sqlMapManager.delete("deleteCrmServiceProductTaOrderByServiceProductIdAndTargetIdAndTargetType",p);
		
	}
	
	public void deleteByServiceProductIdAndTargetIdAndTargetType(Long serviceProductId,Long targetId,String targetType){
		Map p=new HashMap();
		p.put("targetId",targetId);
		p.put("targetType",targetType);
		p.put("serviceProductId",serviceProductId);
		this.sqlMapManager.delete("deleteCrmServiceProductTaOrderByServiceProductIdAndTargetIdAndTargetType",p);
	}
	

}
